class Solution
{
public:
    bool isPalindrome(string s)
    {
        int front = 0;
        int back = s.size() - 1;
        while (front < back)
        {
            if (!isAlphabetOrNum(s[front]))
            {
                ++front;
                continue;
            }
            if (!isAlphabetOrNum(s[back]))
            {
                --back;
                continue;
            }
            if (isSameAlphabetOrNum(s[front], s[back]))
            {
                ++front;
                --back;
            }
            else
            {
                return false;
            }
        }
        return true;
    }

    inline bool isAlphabetOrNum(char c)
    {
        return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
    }

    inline bool isSameAlphabetOrNum(char c1, char c2)
    {
        // c1, c2已经是数字或字母
        return (c1 == c2) || ((c1 >= 'a') && (c1 == c2 - 'A' + 'a')) || ((c2 >= 'a') && (c2 == c1 - 'A' + 'a'));
    }
};